﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SSPevc.Common
{
    public static class BackgroundTask
    {
        /// <summary>
        /// 执行后台任务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="argBackgroundFunc"></param>
        /// <param name="argCompletedAction"></param>
        public static void RunBackgroundTask<T>(Func<T> argBackgroundFunc, Action<T> argCompletedAction)
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (sender, e) => e.Result = argBackgroundFunc();
            if (argCompletedAction != null)
            {
                worker.RunWorkerCompleted += (sender, e) => argCompletedAction((T)e.Result);
            }            
            worker.RunWorkerAsync();
            // test
        }
    }
}
